
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:rfid/page/register_page.dart';
import '../main.dart';
import '../util/timer_manager.dart';
import '../widget/device_name_widget.dart';
import 'help_page.dart';


class RegisterTip extends StatefulWidget {
  const RegisterTip({Key? key}) : super(key: key);

  @override
  State<RegisterTip> createState() => _RegisterTipState();
}

class _RegisterTipState extends State<RegisterTip> {


  @override
  initState() {
    super.initState();

    WidgetsBinding.instance.addPostFrameCallback((_){
      timer.startCountDown(CountDownMode.normal,(){
        currentTask.clear();
        Get.until((route) => route.isFirst);
      });
    });

  }


  _appBar(){
    return Container(
      width: double.infinity,
      height: 42.h,
      alignment: Alignment.center,
      padding: const EdgeInsets.only(left: 20,right: 20).w,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          deviceNameWidget(),
          InkWell(
            onTap: (){
              Get.to(()=> const Help());
            },
            child:  Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [

                Icon(Icons.help,color: Colors.white,size: 20.sp,),
                Text(" 帮助",style: TextStyle(color: Colors.white,fontSize: 12.sp),)
              ],
            ),
          )


        ],
      ),
    );
  }



  _title(){
    return Container(
        margin: EdgeInsets.only(top: 20.h,left: 20.w,right: 20.w),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            InkWell(
              onTap: (){
                Get.back();
              },
              child: Image.asset("assets/images/back.png",width:60.w,height:23.h, fit: BoxFit.fill,),
            ),
            Image.asset("assets/images/register_title.png",height: 21.h,fit: BoxFit.fitHeight,),
            Obx(() => Text("${timer.normalTime.value}s",style: TextStyle(color: Colors.white,fontSize: 12.sp),))
          ],
        )
    );
  }

  _container(){
    return Container(
        decoration:BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.all(Radius.circular(4.r)),
        ),
        margin: EdgeInsets.only(left: 20.w,right: 20.w,top: 20.h),
        padding: EdgeInsets.only(left: 16.w,right: 16.w,top: 12.h,bottom: 6.h),
        width: double.infinity,
        height: 520.h,
        child: Stack(
          alignment: AlignmentDirectional.center,
          children: [
            Positioned(
              top: 0,
              child: Text('办证须知',style: TextStyle(color: Colors.black,fontSize: 12.sp,fontWeight: FontWeight.bold),),
            ),

            SizedBox(height: 16.h,),
            Positioned(
              top: 36.h,
              left: 0,
              child: Image.asset("assets/images/id_tip.png",width: 200.w, fit: BoxFit.fitWidth,),
            ),
            Positioned(
              bottom: 10.h,
              child: InkWell(
                onTap: (){
                  Get.to(()=>const Register());
                },
                child: Image.asset("assets/images/confirm.png",width: 80.w, fit: BoxFit.fitWidth,),
              )
            ),

          ],
        ),
    );
  }


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        width: double.infinity,
        height: double.infinity,
        decoration: const BoxDecoration(
          image: DecorationImage(
            fit: BoxFit.fill,
            image: AssetImage(
              "assets/images/bg.png",
            ),
          ),
        ),
        child: Column(
          children: [
            _appBar(),
            _title(),
            _container()
          ],
        ),
      ),
    );
  }
}

